<?php

namespace backend\models;

use Yii;
use yii\helpers\ArrayHelper;
/**
 * This is the model class for table "contractor".
 *
 * @property int $id
 * @property string|null $inn
 * @property string|null $kpp
 * @property string|null $ogrn
 * @property string|null $name
 * @property string|null $name_full_opf
 * @property string|null $name_short_opf
 * @property string|null $fio_ip
 * @property string|null $okpo
 * @property string|null $management
 * @property string|null $address
 * @property string|null $email
 * @property string|null $phone
 */
class Contractor extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'contractor';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['inn'], 'unique'],
            [['inn', 'kpp', 'ogrn', 'name', 'name_full_opf', 'name_short_opf', 'fio_ip', 'okpo', 'management', 'address', 'email', 'phone', 'checking_account', 'correspondent_account', 'bank_name', 'bank_bik'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'inn' => 'ИНН',
            'kpp' => 'КПП',
            'ogrn' => 'ОГРН',
            //'name' => 'Name',
            'name_full_opf' => 'Полное наименование',
            'name_short_opf' => 'Сокращенное наименование',
            //'fio_ip' => 'Fio Ip',
            'okpo' => 'ОКПО',
            'management' => 'Руководитель',
            'address' => 'Адрес',
            'email' => 'Email',
            'phone' => 'Телефон',
            'checking_account' => 'Расчетный счёт',
            'correspondent_account' => 'Корреспондентский счёт',
            'bank_name' => 'Наименование банка',
            'bank_bik' => 'БИК банка',
        ];
    }

    public static function contractorList()
    {
        return ArrayHelper::map(
            self::find()->select(['concat(inn," ",name_short_opf) as name','id'])->orderBy('inn')->asArray()->all(), 
            'id', 
            'name'
        );
    }
}
